/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2016
 */

package com.jzwl.site.manager.node.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jzwl.site.manager.node.dao.SiteNodeDao;


@Service("siteNodeService")
public class SiteNodeService {
	
	
	@Autowired
	private SiteNodeDao siteNodeDao;
	
	public boolean delSiteNode(Map<String, Object> map){
		return siteNodeDao.delSiteNode(map);
	}
	
	public boolean updateSiteNode(Map<String, Object> map) {
		
		return siteNodeDao.updateSiteNode(map);
	}
	
	public boolean addSiteNode(Map<String, Object> map) {
		
		return siteNodeDao.addSiteNode(map);
	}
	
	public Map queryNodeInfoById(Map<String, Object> map) {
		
		return siteNodeDao.getById(map);
	}
	
	public List<Map<String, Object>> queryNodeInfo(Map<String, Object> map){
		Queue<Map<String, Object>> queue = new LinkedList<Map<String, Object>>();
		
		List<Map<String, Object>> treelist = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> list = siteNodeDao.querySiteNodeInfo(map);
		for(int i=0;i<list.size();i++){
			Map<String, Object> nodemap = list.get(i);
			queue.offer(nodemap);
		}
		
		Map<String, String> fontmap = new HashMap<String, String>();
		fontmap.put("font-weight", "bolder");
		fontmap.put("font-size", "16px");
		while(!queue.isEmpty()){
			Map<String, Object> nodemap = queue.poll();
			nodemap.put("font", fontmap);
			nodemap.put("open", true);
			List<Map<String, Object>> chlist = siteNodeDao.querySiteNodeInfo(nodemap);
			if(chlist != null && chlist.size()>0){
				nodemap.put("iconOpen", "../v2/console/images/folderopen.gif");
				nodemap.put("iconClose", "../v2/console/images/folderclosed.gif");
				for(int i=0;i<chlist.size();i++){
					Map<String, Object> nodemap2 = chlist.get(i);
					queue.offer(nodemap2);
				}
			}else{
				nodemap.put("icon", "../v2/console/images/folderclosed.gif");
			}
			treelist.add(nodemap);
		}
		return treelist;
	}
}
